$(function () {
    var flag=0; //删除键的效果切换 0为初始值
    // var contentChooseFlag=0; //内容模块来回切换是否选中
    var myDate= new Date();
    var startYear=myDate.getFullYear()-50;//起始年份
    var endYear=myDate.getFullYear()+50;//结束年份
    var yearSelect=document.getElementById('choseYear_projectManage');
    for (var i=startYear;i<=endYear;i++)
    {
        var option=document.createElement("option");
        option.text=" "+i+'年';
        try{
            // 对于更早的版本IE8
            yearSelect.add(option,yearSelect.options[null]);
        }catch (e){
            yearSelect.add(option,null);
        }
        // yearSelect.options.add(new Option(i,i)+'年');
    }
    yearSelect.options[yearSelect.options.length-51].selected=1;

    //标签页切换操作
    var tab=document.getElementsByClassName('tabNavigation')[0];
    EventUtil.addHandler(tab,"click",function (event) {
        event=EventUtil.getEvent(event);
        var target=EventUtil.getTarget(event);
        // console.log($('.projectALLContent').hasClass('active'))
        switch (target.id){
            case "itemAll":
                if(!$(target).parent().hasClass('active')){
                    $(target).parent().siblings().removeClass('active');
                    $(target).parent().addClass('active');
                }
                if(!$('.projectALLContent').hasClass('active')){
                    $('.projectALLContent').addClass('active');
                    $('.projectALLContent').siblings().removeClass('active');
                }
                break;
            case "itemEstablished":
                // console.log(1)
                // console.log($(target).parent())
                if(!$(target).parent().hasClass('active')){
                    $(target).parent().siblings().removeClass('active');
                    $(target).parent().addClass('active');
                }
                if(!$('.projectEstablishedContent').hasClass('active')){
                    $('.projectEstablishedContent').addClass('active');
                    $('.projectEstablishedContent').siblings().removeClass('active');
                }
                break;
            case "itemFinished":
                if(!$(target).parent().hasClass('active')){
                    // console.log(1)
                    // console.log($(target).parent());
                    $(target).parent().siblings().removeClass('active');
                    $(target).parent().addClass('active');
                    // console.log($(target).parent());
                }
                if(!$('.projectFinishedContent').hasClass('active')){
                    $('.projectFinishedContent').addClass('active');
                    $('.projectFinishedContent').siblings().removeClass('active');
                }
                break;
        }
    })

    //删除点击事件 0 红框 可点击 按钮变蓝 1  删除列表 按钮变白
    var btnDelete=document.getElementsByClassName('deleteOne')[0];
    EventUtil.addHandler(btnDelete,"click",function (event) {
        event = EventUtil.getEvent(event);
        var target = EventUtil.getTarget(event);
        // console.log(target)
        if(!$(target).hasClass('active')){
            // console.log(1)
            $('.itemContent').css("cursor","pointer");
            //是否将查看 导出文件等按钮去掉cursor
            // $('.itemContent').removeClass('boxShadow').addClass('redBoxShadow');
            // $('.partContent').css("box-shadow","0px 0px 1px 3px rgb(230,5,20)");
            // $(target).css('background-color','#00A0E9').css('color','#FFFFFF');
            $(target).addClass('active');
            // console.log(target)

        }
        else if($(target).hasClass('active')){
            // $('.itemContent').css("border","1px solid #FFFFFF");
            // console.log(2)
            $('.itemContent').css("cursor","default");
            // $('.itemContent').removeClass('redBoxShadow').addClass('boxShadow');
            // $('.partContent').css("box-shadow","0px 0px 2px 4px rgb(235,235,235)");
            $(target).removeClass('active');
            // console.log(target)

            //删除灰色背景的li
            //
            // console.log($('.shadePane.active').parent().attr('data-index'))
            let delete_list = $('.shadePane.active').parent()
            let delete_arr = []
            for( let i = 0; i < delete_list.length; i++){
                delete_arr.push($(delete_list[i]).attr('data-index'))
            }
            // console.log(delete_arr)
            $.ajax({
                url:'http://jk.com/Admin/Project/deleteProj',
                type:'post',
                data:{
                    pro_id: delete_arr
                },
                success:function(data){
                    "use strict";
                    if(data.code==1){
                        $('.shadePane.active').parent().remove();
                    }
                }
            })
        }
    });

    //点击变灰
    var actionList=document.getElementsByClassName('projectContent active')[0];
    // console.log(actionList);
    EventUtil.addHandler(actionList,"click",function (event) {
        event=EventUtil.getEvent(event);
        var target=EventUtil.getTarget(event);
        var current=$(target).parents('.itemContent').children('.shadePane');
        // console.log($(target).hasClass('active'))
        if($('.deleteOne').hasClass('active')){
            if(!current.hasClass('active')){
                current.addClass('active');
            }else{
                current.removeClass('active');
            }
        }

        // console.log($(target).parents('.itemContent'));
    })

})